/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package shoppinglist;

import javax.swing.*;
import java.awt.*;
import java.util.Arrays;

/**
 *
 * @author Student
 */
public class ShopPanel extends JPanel {
    
    public JList listbox;
    public DefaultListModel model;
    boolean listDisplay = false;
    public JScrollPane scroll;
    private String[] StringArray;

    public ShopPanel() {
        model = new DefaultListModel();
        setBackground(Color.BLACK);
        setList();
    }

    public String[] getList() {
        setStringArray(Arrays.copyOf(getModel().toArray(), getModel().toArray().length, String[].class));
        return getStringArray();
    }

    private void setList() {
        listbox = new JList(getModel());
        scroll = new JScrollPane(listbox);
        scroll.setPreferredSize(new Dimension(290, 550));
        scroll.setFont(new Font("Arial", Font.BOLD, 20));
        add(scroll);
    }

    public void addToList(String s) {
        if (listDisplay == false) {
            this.model.addElement(s);
        }
    }

    public void loadList(String posts[]) {

        model.clear();
        for (int i = 0; i < posts.length; i++) {
            model.addElement(posts[i]);
        }

    }

    /**
     * @return the model
     */
    public DefaultListModel getModel() {
        return model;
    }

    /**
     * @param model the model to set
     */
    public void setModel(DefaultListModel model) {
        this.model = model;
    }

    /**
     * @return the StringArray
     */
    public String[] getStringArray() {
        return StringArray;
    }

    /**
     * @param StringArray the StringArray to set
     */
    public void setStringArray(String[] StringArray) {
        this.StringArray = StringArray;
    }

}
